/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.handler.props;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "captcha")
public class CaptchaProps {
    private boolean enabled = true;
    private Case[] cases;

    /**
     * 验证时传递用户验证码信息给服务器的参数名称
     */
    private String paramName = "_v";
    private String logout = "/logout";
    private Out out;

    public Case[] getCases() {
        return cases;
    }

    public void setCases(Case[] cases) {
        this.cases = cases;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public String getParamName() {
        return paramName;
    }

    public String getLogout() {
        return logout;
    }

    public void setLogout(String logout) {
        this.logout = logout;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    public Out getOut() {
        return out;
    }

    public void setOut(Out out) {
        this.out = out;
    }

    public static class Case {
        String type = "text";
        String[] openPaths;
        String[] protectPaths;

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String[] getPaths() {
            String[] paths = new String[getOpenPaths().length + getProtectPaths().length];
            System.arraycopy(getOpenPaths(), 0, paths, 0, getOpenPaths().length);
            System.arraycopy(getProtectPaths(), 0, paths, getOpenPaths().length, getProtectPaths().length);
            return paths;
        }

        public String[] getOpenPaths() {
            return openPaths == null ? new String[0] : openPaths;
        }

        public void setOpenPaths(String[] openPaths) {
            this.openPaths = openPaths;
        }

        public String[] getProtectPaths() {
            return protectPaths == null ? new String[0] : protectPaths;
        }

        public void setProtectPaths(String[] protectPaths) {
            this.protectPaths = protectPaths;
        }
    }

    public static class Out {
        private int width = 200;
        private int height = 80;
        private int fontSize = 60;
        private String[] fonts = new String[]{};

        public Out() {

        }

        public int getWidth() {
            return width;
        }

        public void setWidth(int width) {
            this.width = width;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public int getFontSize() {
            return fontSize;
        }

        public void setFontSize(int fontSize) {
            this.fontSize = fontSize;
        }

        public String[] getFonts() {
            return fonts;
        }

        public void setFonts(String[] fonts) {
            this.fonts = fonts;
        }
    }
}
